package com.android.mios.adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.android.mios.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BottomNavigationGridViewAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<? extends Map<String, ?>> mList;
	private int resource;
	public static final String TEXT_TITLE = "texttitle";
	public static final String IMAGE = "image";

	private int selectItem = 0;

	public BottomNavigationGridViewAdapter(Context context,
			ArrayList<HashMap<String, Object>> data, int resource) {
		mInflater = LayoutInflater.from(context);
		mList = data;
		this.resource = resource;
	}

	public void setSelectItem(int selectItem) {
		this.selectItem = selectItem;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null)
			convertView = mInflater.inflate(resource, null);

		if (position == selectItem) {
			convertView.setBackgroundResource(R.drawable.gv_item_pressed_bg);
		} else {
			convertView.setBackgroundResource(R.drawable.gv_item_normal_bg);
		}
		
		TextView tvTitle = (TextView) convertView
				.findViewById(R.id.txt_bottomt_navigation);

		ImageView img = (ImageView) convertView
				.findViewById(R.id.img_bottom_navigation);

		Map<String, ?> map = mList.get(position);
		String title = (String) map.get(TEXT_TITLE);
		tvTitle.setText(title);
		img.setImageResource((Integer) map.get(IMAGE));

		return convertView;
	}

}
